home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / mrdo.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  6KB  |  227 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. unsigned char *mrdo_bgvideoram,*mrdo_fgvideoram;
  14. static struct tilemap *bg_tilemap,*fg_tilemap;
  15. static int flipscreen;
  16.  
  17.  
  18.  
  19. /***************************************************************************
  20.  
  21.   Convert the color PROMs into a more useable format.
  22.  
  23.   Mr. Do! has two 32 bytes palette PROM and a 32 bytes sprite color lookup
  24.   table PROM.
  25.   The palette PROMs are connected to the RGB output this way:
  26.  
  27.   U2:
  28.   bit 7 -- unused
  29.         -- unused
  30.         -- 100 ohm resistor  -- BLUE
  31.         --  75 ohm resistor  -- BLUE
  32.         -- 100 ohm resistor  -- GREEN
  33.         --  75 ohm resistor  -- GREEN
  34.         -- 100 ohm resistor  -- RED
  35.   bit 0 --  75 ohm resistor  -- RED
  36.  
  37.   T2:
  38.   bit 7 -- unused
  39.         -- unused
  40.         -- 150 ohm resistor  -- BLUE
  41.         -- 120 ohm resistor  -- BLUE
  42.         -- 150 ohm resistor  -- GREEN
  43.         -- 120 ohm resistor  -- GREEN
  44.         -- 150 ohm resistor  -- RED
  45.   bit 0 -- 120 ohm resistor  -- RED
  46.  
  47. ***************************************************************************/
  48. void mrdo_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  49. {
  50.     int i;
  51.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  52.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  53.  
  54.  
  55.     for (i = 0;i < 256;i++)
  56.     {
  57.         int a1,a2;
  58.         int bit0,bit1,bit2,bit3;
  59.  
  60.  
  61.         a1 = ((i >> 3) & 0x1c) + (i & 0x03) + 32;
  62.         a2 = ((i >> 0) & 0x1c) + (i & 0x03);
  63.  
  64.         bit0 = (color_prom[a1] >> 1) & 0x01;
  65.         bit1 = (color_prom[a1] >> 0) & 0x01;
  66.         bit2 = (color_prom[a2] >> 1) & 0x01;
  67.         bit3 = (color_prom[a2] >> 0) & 0x01;
  68.         *(palette++) = 0x2c * bit0 + 0x37 * bit1 + 0x43 * bit2 + 0x59 * bit3;
  69.         bit0 = (color_prom[a1] >> 3) & 0x01;
  70.         bit1 = (color_prom[a1] >> 2) & 0x01;
  71.         bit2 = (color_prom[a2] >> 3) & 0x01;
  72.         bit3 = (color_prom[a2] >> 2) & 0x01;
  73.         *(palette++) = 0x2c * bit0 + 0x37 * bit1 + 0x43 * bit2 + 0x59 * bit3;
  74.         bit0 = (color_prom[a1] >> 5) & 0x01;
  75.         bit1 = (color_prom[a1] >> 4) & 0x01;
  76.         bit2 = (color_prom[a2] >> 5) & 0x01;
  77.         bit3 = (color_prom[a2] >> 4) & 0x01;
  78.         *(palette++) = 0x2c * bit0 + 0x37 * bit1 + 0x43 * bit2 + 0x59 * bit3;
  79.     }
  80.  
  81.     color_prom += 64;
  82.  
  83.     /* sprites */
  84.     for (i = 0;i < TOTAL_COLORS(2);i++)
  85.     {
  86.         int bits;
  87.  
  88.         if (i < 32)
  89.             bits = color_prom[i] & 0x0f;        /* low 4 bits are for sprite color n */
  90.         else
  91.             bits = color_prom[i & 0x1f] >> 4;    /* high 4 bits are for sprite color n + 8 */
  92.  
  93.         COLOR(2,i) = bits + ((bits & 0x0c) << 3);
  94.     }
  95. }
  96.  
  97.  
  98.  
  99. /***************************************************************************
  100.  
  101.   Callbacks for the TileMap code
  102.  
  103. ***************************************************************************/
  104.  
  105. static void get_bg_tile_info(int tile_index)
  106. {
  107.     unsigned char attr = mrdo_bgvideoram[tile_index];
  108.     SET_TILE_INFO(1,mrdo_bgvideoram[tile_index+0x400] + ((attr & 0x80) << 1),attr & 0x3f)
  109.     tile_info.flags = TILE_SPLIT((attr & 0x40) >> 6);
  110. }
  111.  
  112. static void get_fg_tile_info(int tile_index)
  113. {
  114.     unsigned char attr = mrdo_fgvideoram[tile_index];
  115.     SET_TILE_INFO(0,mrdo_fgvideoram[tile_index+0x400] + ((attr & 0x80) << 1),attr & 0x3f)
  116.     tile_info.flags = TILE_SPLIT((attr & 0x40) >> 6);
  117. }
  118.  
  119.  
  120.  
  121. /***************************************************************************
  122.  
  123.   Start the video hardware emulation.
  124.  
  125. ***************************************************************************/
  126.  
  127. int mrdo_vh_start(void)
  128. {
  129.     bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,TILEMAP_SPLIT,8,8,32,32);
  130.     fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_SPLIT,8,8,32,32);
  131.  
  132.     if (!bg_tilemap || !fg_tilemap)
  133.         return 1;
  134.  
  135.     bg_tilemap->transmask[0] = 0x01; /* split type 0 has pen 1 transparent in front half */
  136.     bg_tilemap->transmask[1] = 0x00; /* split type 1 is totally opaque in front half */
  137.     fg_tilemap->transmask[0] = 0x01; /* split type 0 has pen 1 transparent in front half */
  138.     fg_tilemap->transmask[1] = 0x00; /* split type 1 is totally opaque in front half */
  139.  
  140.     return 0;
  141. }
  142.  
  143.  
  144.  
  145. /***************************************************************************
  146.  
  147.   Memory handlers
  148.  
  149. ***************************************************************************/
  150.  
  151. WRITE_HANDLER( mrdo_bgvideoram_w )
  152. {
  153.     if (mrdo_bgvideoram[offset] != data)
  154.     {
  155.         mrdo_bgvideoram[offset] = data;
  156.         tilemap_mark_tile_dirty(bg_tilemap,offset & 0x3ff);
  157.     }
  158. }
  159.  
  160. WRITE_HANDLER( mrdo_fgvideoram_w )
  161. {
  162.     if (mrdo_fgvideoram[offset] != data)
  163.     {
  164.         mrdo_fgvideoram[offset] = data;
  165.         tilemap_mark_tile_dirty(fg_tilemap,offset & 0x3ff);
  166.     }
  167. }
  168.  
  169.  
  170. WRITE_HANDLER( mrdo_scrollx_w )
  171. {
  172.     tilemap_set_scrollx(bg_tilemap,0,data);
  173. }
  174.  
  175. WRITE_HANDLER( mrdo_scrolly_w )
  176. {
  177.     tilemap_set_scrolly(bg_tilemap,0,data);
  178. }
  179.  
  180.  
  181. WRITE_HANDLER( mrdo_flipscreen_w )
  182. {
  183.     /* bits 1-3 control the playfield priority, but they are not used by */
  184.     /* Mr. Do! so we don't emulate them */
  185.  
  186.     flipscreen = data & 0x01;
  187.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  188. }
  189.  
  190.  
  191.  
  192. /***************************************************************************
  193.  
  194.   Display refresh
  195.  
  196. ***************************************************************************/
  197.  
  198. static void draw_sprites(struct osd_bitmap *bitmap)
  199. {
  200.     int offs;
  201.  
  202.  
  203.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  204.     {
  205.         if (spriteram[offs + 1] != 0)
  206.         {
  207.             drawgfx(bitmap,Machine->gfx[2],
  208.                     spriteram[offs],spriteram[offs + 2] & 0x0f,
  209.                     spriteram[offs + 2] & 0x10,spriteram[offs + 2] & 0x20,
  210.                     spriteram[offs + 3],256 - spriteram[offs + 1],
  211.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  212.         }
  213.     }
  214. }
  215.  
  216. void mrdo_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  217. {
  218.     tilemap_update(ALL_TILEMAPS);
  219.  
  220.     tilemap_render(ALL_TILEMAPS);
  221.  
  222.     fillbitmap(bitmap,Machine->pens[0],&Machine->drv->visible_area);
  223.     tilemap_draw(bitmap,bg_tilemap,TILEMAP_FRONT);
  224.     tilemap_draw(bitmap,fg_tilemap,TILEMAP_FRONT);
  225.     draw_sprites(bitmap);
  226. }
  227.